let transfer = document.getElementById('transferBtn');
transfer.addEventListener('click', function () {
    let login = document.querySelector('.login-box');
    let reg = document.querySelector('.reg-box');
    let total = document.querySelector('.transition-box');
    let target = document.querySelector('.transferToReg');
    let title = document.querySelector('.title');
    let subTitle = document.querySelector('.subTitle');
    transfer.innerText === '注册'
        ? (() => {
            target.style.left = 0;
            total.style.left = 260 + 'px';
            transfer.innerText = '登录';
            title.innerText = '已有帐号？';
            subTitle.innerText = '有帐号就登录吧，好久不见了！';
            setTimeout(() => {
                login.style.display = 'none';
                reg.style.display = 'flex';
            }, 300);
        })()
        : (() => {
            target.style.left = 640 + 'px';
            total.style.left = 0;
            transfer.innerText = '注册';
            title.innerText = '还未注册？';
            subTitle.innerText = '立即注册，发现大量机会！';
            setTimeout(() => {
                login.style.display = 'flex';
                reg.style.display = 'none';
            }, 300);
        })();
});

// 登录
document.getElementById('login').addEventListener('click', function () {
    let username = document.getElementById('login-username');
    let password = document.getElementById('login-password');
    let tenant = document.getElementById('login-tenant');
    var data = {
        tenantId: tenant.value,
        grant_type: 'password',
        uname: username.value,
        pwd: password.value
    };
    var result = sendPost('/auth/login', null, data, false);
    if (result) {
        result.then(function (res) {
            if (res.status === 200) {
                var data = JSON.parse(res.result);
                if (data.code === 200) {
                    goToUrl('view/index')
                } else {
                    alert(data.message);
                }
            }
        });
    }
});
// 注册
document.getElementById('reg').addEventListener('click', function () {
    let username = document.getElementById('reg-username');
    let password = document.getElementById('reg-password');
    let tenant = document.getElementById('reg-tenant');
    var data = {
        tenantId: tenant.value,
        username: username.value,
        password: password.value
    };
    var result = sendPost('/auth/register', null, data, false);
    if (result) {
        if (result.code === 200) {
            goToUrl('view/login')
        } else {
            alert(result.message);
        }
    }
});